package com.antunnel.betting.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.antunnel.betting.service.ElevenTakeFiveService;
import com.antunnel.common.util.Combination;
import com.antunnel.common.util.ElevenTakeFive;

/**
 * 11选5
 * @author ning.wang
 *
 */
public class ElevenTakeFiveServiceImpl implements ElevenTakeFiveService{

	/**
	 * 前一
	 */
	public Map<String, Object> frontOne(String number) throws Exception {
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null){
			Integer  selectedbetcount = number.length()/2;
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer achieve=ElevenTakeFive.FRONTONEBONUS-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", ElevenTakeFive.FRONTONEBONUS);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.FRONTONEBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	/**
	 * 前二
	 * @param number
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object>  frontTwo(String wanwei,String qianwei) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(wanwei!=null && qianwei!=null){
			Integer wanweiNum=wanwei.length()/2;
			Integer qianweiNum=qianwei.length()/2;
			Integer  selectedbetcount =wanweiNum*qianweiNum;
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer achieve=ElevenTakeFive.FRONTTWOBONUS-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", ElevenTakeFive.FRONTTWOBONUS);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.FRONTTWOBONUS);
			map.put("achieve", 0);
			return map;
		}
	}

	/**
	 * 前二组选
	 * @param num
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> frontTwoZuXuan(String number) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null){
			Integer selectedbetcount=Combination.getCombination(new int[number.length()/2], 2).size();
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer achieve=ElevenTakeFive.FRONTTWOBONUS-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", ElevenTakeFive.FRONTTWOBONUS);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.FRONTTWOZUXUANBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	/**
	 * 前三直选
	 * @param wanwei
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> frontThreeZhiXuan(String wanwei,String qianwei,String gewei) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(wanwei!=null && qianwei!=null && gewei!=null){
			Integer wanweiNum=wanwei.length()/2;
			Integer qianweiNum=qianwei.length()/2;
			Integer geweiNum=gewei.length()/2;
			Integer selectedbetcount=wanweiNum*qianweiNum*geweiNum;
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer achieve=ElevenTakeFive.FRONTTHREEZHIXUANBONUS-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", ElevenTakeFive.FRONTTHREEZHIXUANBONUS);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.FRONTTHREEZHIXUANBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	/**
	 * 前三组选
	 * @param wanwei
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> frontThreeZuXuan(String number) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null){
			Integer selectedbetcount=Combination.getCombination(new int[number.length()/2], 2).size();
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer achieve=ElevenTakeFive.FRONTTHREEZUXUANBONUS-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", ElevenTakeFive.FRONTTHREEZUXUANBONUS);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.FRONTTHREEZUXUANBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	/**
	 * 任八
	 * @param number
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> anyEight(String number) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null && number.length()>=8){
			Integer numCount=number.length()/2;
			Integer selectedbetcount=Combination.getCombination(numCount, 8);
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer betprice=Combination.getCombination(numCount-5, 3)*ElevenTakeFive.ANYEIGHTBONUS;
			Integer achieve=betprice-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", betprice);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.ANYEIGHTBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	/**
	 * 任七
	 * @param number
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> anySeven(String number) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null && number.length()>=7){
			Integer numCount=number.length()/2;
			Integer selectedbetcount=Combination.getCombination(numCount, 7);
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer betprice=Combination.getCombination(numCount-5, 2)*ElevenTakeFive.ANYSEVENBONUS;
			Integer achieve=betprice-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", betprice);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.ANYSEVENBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	/**
	 * 任六
	 * @param number
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> anySix(String number) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null && number.length()>=6){
			Integer numCount=number.length()/2;
			Integer selectedbetcount=Combination.getCombination(numCount, 6);
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer betprice=Combination.getCombination(numCount-5, 1) * ElevenTakeFive.ANYSIXBONUS;
			Integer achieve=betprice-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", betprice);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.ANYSIXBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	/**
	 * 任五
	 * @param number
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> anyFive(String number) throws Exception{
		Map<String,Object> map=new HashMap<String,Object>();
		if(number!=null && number.length()>=5){
			Integer numCount=number.length()/2;
			Integer selectedbetcount=Combination.getCombination(numCount, 5);
			Integer totalcost = ElevenTakeFive.PERBETCOST * selectedbetcount;
			Integer betprice=Combination.getCombination(numCount-5, 0) * ElevenTakeFive.ANYFIVEBONUS;
			Integer achieve=betprice-totalcost;
			map.put("selectedbetcount", selectedbetcount);
			map.put("totalcost", totalcost);
			map.put("betprice", betprice);
			map.put("achieve", achieve);
			return map;
		}else{
			map.put("selectedbetcount", 0);
			map.put("totalcost", 0);
			map.put("betprice", ElevenTakeFive.ANYFIVEBONUS);
			map.put("achieve", 0);
			return map;
		}
	}
	
	public static void main(String[] args) throws Exception {
		ElevenTakeFiveServiceImpl aaa= new ElevenTakeFiveServiceImpl();
		System.out.println(aaa.anyFive("01020304050607080910"));
	}

}
